package com.fenghongzhang.day009;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class SchoolOpenHelp extends SQLiteOpenHelper {

    public SchoolOpenHelp(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    //创建
    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建表格.
        db.execSQL("create table course(id integer primary key autoincrement, name varchar(30),address varchar(30))");

        db.beginTransaction();
        db.execSQL("insert into course(name,address) values(?,?)",new Object[]{"小白","北京"});
        db.execSQL("insert into course(name,address) values(?,?)",new Object[]{"小白","北京"});
        db.execSQL("insert into course(name,address) values(?,?)",new Object[]{"小白","北京"});
        db.execSQL("insert into course(name,address) values(?,?)",new Object[]{"小白","北京"});
        db.execSQL("insert into course(name,address) values(?,?)",new Object[]{"小白","北京"});
        db.setTransactionSuccessful();
        db.endTransaction();
    }

    //更新
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
